package rms.mall.server.starter.exception;



import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import rms.mall.server.api.enums.ErrorCode;
import rms.mall.server.api.module.Result;
import rms.mall.server.domain.exception.BizException;

@Slf4j
@RestControllerAdvice
public class ExceptionController {


    @ExceptionHandler(value = BizException.class)
    public Result bizException(BizException e) {
        log.error("ExceptionController.bizException", e);
        return Result.error(e.getCode(), e.getMsg());
    }

    @ExceptionHandler(value = Exception.class)
    public Result exception(Exception e) {
        log.error("ExceptionController.exception", e);
        return Result.error(ErrorCode.SYSTEM_ERROR.getCode(), ErrorCode.SYSTEM_ERROR.getMsg());
    }

}
